package test;



import com.sleepycat.db.DatabaseException;

import fr.cephb.joperon.core.Operon;
import fr.cephb.joperon.core.db.SnpIdsDB;
import fr.cephb.joperon.core.entities.SnpIds;
import fr.cephb.joperon.tool.OperonFactory;
import fr.cephb.lang.Endian;

/*
 
this example shows how to use an iterator
to list a large set of results

 */
public class Example030
	{
	public static void main(String[] args)
		{
		Endian.setDefault(Endian.CNG);
		Operon operon=null;
		OperonFactory factory = null;
		SnpIdsDB.ValueIterator iter=null;
		try {
			operon= Operon.newInstance();
			//open a factory  with the default assembly
			factory= new OperonFactory(operon);
			
			
			if(!factory.isSnpIdsExists())
				{
				throw new DatabaseException("no database for this assembly "+factory.getAssembly());
				}
			
			//loop over all values
			iter=factory.getSnpIds().listValues();
			
			while(iter.hasNext())
				{
				SnpIds snpid= iter.next();
				System.out.println(snpid.getChromosome()+"\t"+snpid.getPosition());
				}
			
			} 
		catch (Exception e) {
			//print error if any
			e.printStackTrace();
			}
		finally
			{
			//ALWAYS close the iterator
			if(iter!=null) iter.close();
			//ALWAYS close the factory
			if(factory!=null) factory.close();
			//ALWAYS close operon
			if(operon!=null) operon.safeClose();
			}
		}
	}
